home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / c / ObjectiveGT1_0.lha / Examples / Lattice / viewfile.c < prev   
C/C++ Source or Header  |  1992-10-21  |  10KB  |  305 lines

  1. /*
  2. ** $Filename: viewfile.c $
  3. ** $Release : 1.0        $
  4. ** $Revision: 1.258      $
  5. ** $Date    : 21/10/92   $
  6. **
  7. **
  8. ** (C) Copyright 1992 Davide Massarenti
  9. **              All Rights Reserved
  10. **
  11. ** SAS 5.10: lc -O -v -L+OGTglue.lib viewfile.c
  12. **
  13. */
  14.  
  15. #include <OGT/ObjectiveGadTools.h>
  16.  
  17. #define ARGS_TEMPLATE "FILE/K,FONT/K,SIZE/N"
  18. #define ARGS_FILE       (0)
  19. #define ARGS_FONT       (1)
  20. #define ARGS_SIZE       (2)
  21. #define ARGS_NUMOF      (3)
  22.  
  23. static LONG args[ ARGS_NUMOF ];
  24.  
  25. #define GADGETID_SHOWLIST  (1)
  26.  
  27. static char Class_AslReq  [] =   ASLREQ_OGT_CLASS;
  28. static char Class_Scroller[] = SCROLLER_OGT_CLASS;
  29. static char Class_Showlist[] = SHOWLIST_OGT_CLASS;
  30.  
  31. struct TextAttr   MyAttr = { NULL, 8 };
  32. struct TextFont  *MyFont;
  33.  
  34. APTR              VInfo;
  35. struct Window    *Win;
  36. Object          **Gads;
  37. struct RDArgs    *Ra;
  38.  
  39.  
  40. struct TagItem WindowDescTags[] =
  41. {
  42.    { OVI_GimmeZeroZero    , TRUE                                  },
  43.    { OVI_AdaptWidthToFont , TRUE                                  },
  44.    { OVI_AdaptHeightToFont, TRUE                                  },
  45.    { OGT_ScaleLeft        , OGT_FontRelative                      },
  46.    { OGT_ScaleTop         , OGT_FontRelative                      },
  47.    { OGT_ScaleWidth       , OGT_FontRelative                      },
  48.    { OGT_ScaleHeight      , OGT_FontRelative                      },
  49.    { OGT_DomainXscale     , ~0                                    },
  50.    { OGT_DomainYscale     , ~0                                    },
  51.    { WA_Title             , (ULONG)"ViewFile"                     },
  52.    { WA_Activate          , TRUE                                  },
  53.    { WA_SmartRefresh      , TRUE                                  },
  54.    { WA_NoCareRefresh     , TRUE                                  },
  55.    { WA_DepthGadget       , TRUE                                  },
  56.    { WA_SizeGadget        , TRUE                                  },
  57.    { WA_SizeBBottom       , TRUE                                  },
  58.    { WA_SizeBRight        , TRUE                                  },
  59.    { WA_DragBar           , TRUE                                  },
  60.    { WA_Left              , 400                                   },
  61.    { WA_Top               , 150                                   },
  62.    { WA_InnerWidth        , 306                                   },
  63.    { WA_InnerHeight       , 120                                   },
  64.    { WA_MaxWidth          , -1                                    },
  65.    { WA_MaxHeight         , -1                                    },
  66.    { WA_IDCMP             , IDCMP_CLOSEWINDOW | IDCMP_IDCMPUPDATE },
  67.    { WA_CloseGadget       , TRUE                                  },
  68.    { TAG_DONE                                                     }
  69. };
  70.  
  71.  
  72. struct TagItem Object1Desc[] = /* ASLREQ_OGT_CLASS */
  73. {
  74.    { OGT_SetDimReference, OGT_X_Dim_Relative },
  75.    { OGT_SetPosHandle   , OGT_Y_Bottom       },
  76.    { GA_RelBottom       , 0                  },
  77.    { GA_Height          , 14                 },
  78.  
  79.    { GA_Text            , (ULONG)"_F"        },
  80.    { OGT_TextPlacement  , OGT_Text_HIDE      },
  81.  
  82.    { OGTAR_Type         , ASL_FileRequest    },
  83.    { OGTAR_ShowSelected , TRUE               },
  84.    { TAG_DONE                                }
  85. };
  86.  
  87. struct TagItem Object1Post[] =
  88. {
  89.    { OGTAR_FullFileName },
  90.    { TAG_DONE           }
  91. };
  92.  
  93.  
  94. struct TagItem Object2Desc[] = /* SCROLLER_OGT_CLASS */
  95. {
  96.    { GA_Immediate       , TRUE                                    },
  97.    { GA_FollowMouse     , TRUE                                    },
  98.    { GA_RelVerify       , TRUE                                    },
  99.    { ICA_TARGET         , NULL                                    },
  100.  
  101.    { OGT_SetDimReference, OGT_X_Dim_Relative | OGT_Y_Dim_Relative },
  102.    { GA_RightBorder     , TRUE                                    },
  103.  
  104.    { PGA_Freedom        , FREEVERT                                },
  105.    { TAG_DONE                                                     }
  106. };
  107.  
  108.  
  109. struct TagItem Object3Desc[] = /* SCROLLER_OGT_CLASS */
  110. {
  111.    { GA_Immediate       , TRUE                                    },
  112.    { GA_FollowMouse     , TRUE                                    },
  113.    { GA_RelVerify       , TRUE                                    },
  114.    { ICA_TARGET         , NULL                                    },
  115.  
  116.    { OGT_SetDimReference, OGT_X_Dim_Relative | OGT_Y_Dim_Relative },
  117.    { GA_BottomBorder    , TRUE                                    },
  118.  
  119.    { PGA_Freedom        , FREEHORIZ                               },
  120.    { TAG_DONE                                                     }
  121. };
  122.  
  123.  
  124. struct TagItem Object4Desc[] = /* SHOWLIST_OGT_CLASS */
  125. {
  126.    { GA_ID              , GADGETID_SHOWLIST                     },
  127.    { OGT_AppGadget      , TRUE                                  },
  128.    { GA_Immediate       , TRUE                                  },
  129.    { GA_FollowMouse     , TRUE                                  },
  130.    { GA_RelVerify       , TRUE                                  },
  131.  
  132.    { OGT_SetDimReference, OGT_X_Dim_Relative|OGT_Y_Dim_Relative },
  133.    { GA_Height          , -14                                   },
  134.  
  135.    { OGTSL_UseNumPad    , TRUE                                  },
  136.    { TAG_DONE                                                   }
  137. };
  138.  
  139. struct OGT_ObjectSettings ListOfObjects[] =
  140. {
  141.    { Class_AslReq  , Object1Desc, Object1Post, OGT_NOOBJECT, OGT_NOOBJECT },
  142.    { Class_Scroller, Object2Desc, NULL       , OGT_NOOBJECT, OGT_NOOBJECT },
  143.    { Class_Scroller, Object3Desc, NULL       , OGT_NOOBJECT, OGT_NOOBJECT },
  144.    { Class_Showlist, Object4Desc, NULL       , OGT_NOOBJECT, OGT_NOOBJECT },
  145.    { NULL                                                                 },
  146. };
  147.  
  148.  
  149.  
  150. struct TagItem Obj2toObj4[] =    /* SCROLLER_OGT_CLASS to SHOWLIST_OGT_CLASS */
  151. {
  152.    { PGA_Top , OGTSL_VertPos },
  153.    { TAG_DONE                }
  154. };
  155.  
  156.  
  157. struct TagItem Obj3toObj4[] =    /* SCROLLER_OGT_CLASS to SHOWLIST_OGT_CLASS */
  158. {
  159.    { PGA_Top , OGTSL_HoriPos },
  160.    { TAG_DONE                }
  161. };
  162.  
  163.  
  164. struct TagItem Obj4toObj2[] =    /* SHOWLIST_OGT_CLASS to SCROLLER_OGT_CLASS */
  165. {
  166.    { OGTSL_VertPos    , PGA_Top     },
  167.    { OGTSL_VertTotal  , PGA_Total   },
  168.    { OGTSL_VertVisible, PGA_Visible },
  169.    { TAG_DONE                       }
  170. };
  171.  
  172. Tag Obj4toObj2Filter[] =
  173. {
  174.    OGTSL_VertPos    ,
  175.    OGTSL_VertTotal  ,
  176.    OGTSL_VertVisible,
  177.    TAG_DONE
  178. };
  179.  
  180.  
  181. struct TagItem Obj4toObj3[] =    /* SHOWLIST_OGT_CLASS to SCROLLER_OGT_CLASS */
  182. {
  183.    { OGTSL_HoriPos    , PGA_Top     },
  184.    { OGTSL_HoriTotal  , PGA_Total   },
  185.    { OGTSL_HoriVisible, PGA_Visible },
  186.    { TAG_DONE                       }
  187. };
  188.  
  189. Tag Obj4toObj3Filter[] =
  190. {
  191.    OGTSL_HoriPos    ,
  192.    OGTSL_HoriTotal  ,
  193.    OGTSL_HoriVisible,
  194.    TAG_DONE
  195. };
  196.  
  197.  
  198. struct TagItem Obj1toObj4[] =    /* ASLREQ_OGT_CLASS to SHOWLIST_OGT_CLASS */
  199. {
  200.    { OGTAR_FullFileName, OGTSL_FileToLoadByName },
  201.    { TAG_DONE                                   }
  202. };
  203.  
  204. Tag Obj1toObj4Filter[] =
  205. {
  206.    OGTAR_FullFileName,
  207.    TAG_DONE
  208. };
  209.  
  210.  
  211. struct OGT_ObjectLink ListOfLinks[] =
  212. {
  213.    { 3           , 1, Obj4toObj2, Obj4toObj2Filter },
  214.    { 3           , 2, Obj4toObj3, Obj4toObj3Filter },
  215.    { 1           , 3, Obj2toObj4                   },
  216.    { 2           , 3, Obj3toObj4                   },
  217.  
  218.    { 0           , 3, Obj1toObj4, Obj1toObj4Filter },
  219.  
  220.    { OGT_NOOBJECT                                  },
  221. };
  222.  
  223.  
  224. static int cleanup( char *str );
  225.  
  226. int main( void )
  227. {
  228.    if(!OpenOGT()) cleanup( "no objectivegadtools.library!\n" );
  229.  
  230.    if(!(Ra = ReadArgs( ARGS_TEMPLATE, args, NULL ))) return( cleanup( "Can't parse args\n" ) );
  231.  
  232.    if(args[ ARGS_FONT ]) MyAttr.ta_Name  =  (STRPTR )args[ ARGS_FONT ];
  233.    if(args[ ARGS_SIZE ]) MyAttr.ta_YSize = *(ULONG *)args[ ARGS_SIZE ];
  234.  
  235.    if(MyAttr.ta_Name)
  236.    {
  237.       if(!(MyFont = OpenDiskFont( &MyAttr ))) return( cleanup( "Can't open font!!\n" ) );
  238.    }
  239.  
  240.    while(1)
  241.    {
  242.       VInfo = OGT_GetVisualInfo( NULL, OGT_TextFont, (ULONG)MyFont         ,
  243.                                        TAG_MORE    , (ULONG)WindowDescTags );
  244.  
  245.       if(VInfo == NULL) return( cleanup( "Can't open my window.\n" ) );
  246.  
  247.       Object1Post[ 0 ].ti_Data = args[ ARGS_FILE ];
  248.  
  249.       if(!OGT_BuildObjects( VInfo, ListOfObjects, ListOfLinks, &Gads )) return( cleanup( "can't create objects" ) );
  250.  
  251.       Win = OGT_GetWindowPtr( VInfo );
  252.  
  253.       {
  254.          BOOL keeprunning = TRUE;
  255.  
  256.          while(keeprunning)
  257.          {
  258.             struct IntuiMessage *imsg;
  259.  
  260.             Wait( 1L << Win->UserPort->mp_SigBit );
  261.  
  262.             while(keeprunning && (imsg = OGT_GetMsg( VInfo )))
  263.             {
  264.                switch(imsg->Class)
  265.                {
  266.                   case IDCMP_CLOSEWINDOW:
  267.                      keeprunning = FALSE;
  268.                      break;
  269.  
  270.                   case IDCMP_IDCMPUPDATE:
  271.                      if(OGT_GetLastTagData( OGT_ID, 0, imsg->IAddress ) == GADGETID_SHOWLIST) /* SHOWLIST_OGT_CLASS */
  272.                      {
  273.                         STRPTR icon = (APTR)OGT_GetLastTagData( OGT_DroppedIcon, NULL, imsg->IAddress );
  274.  
  275.                         if(icon) SetGadgetAttrs( Gads[ 0 ], Win, NULL, OGTAR_FullFileName, (ULONG)icon, TAG_DONE );
  276.                      }
  277.  
  278.                      break;
  279.                }
  280.  
  281.                OGT_ReplyMsg( imsg );
  282.             }
  283.          }
  284.       }
  285.  
  286.       break;
  287.    }
  288.  
  289.    return( cleanup( NULL ) );
  290. }
  291.  
  292. static int cleanup( char *str )
  293. {
  294.    if(str) Printf( "%s\n", str );
  295.  
  296.    if(Ra    ) FreeArgs          ( Ra     );
  297.    if(Gads  ) FreeVec           ( Gads   );
  298.    if(VInfo ) OGT_FreeVisualInfo( VInfo  );
  299.    if(MyFont) CloseFont         ( MyFont );
  300.  
  301.    CloseOGT();
  302.  
  303.    return( str ? 10 : 0 );
  304. }
  305.